using Godot;
using VexelDict = Godot.Collections.Dictionary<Godot.Vector3I, uint>;

public partial class TerrainGenerator : Resource
{
	const float RANDOM_BLOCK_PROBABILITY = 0.015f;
	
	public static VexelDict empty()
	{
		return new VexelDict();
	}

	public static VexelDict RandomBlocks()
	{
		VexelDict random_data = new VexelDict();
		for (int x = 0; x < VoxelWorld.CHUNK_SIZE; x++)
		{
			for (int y = 0; y < VoxelWorld.CHUNK_SIZE; y++)
			{
				for (int z = 0; z < VoxelWorld.CHUNK_SIZE; z++)
				{
					Vector3I vec = new Vector3I(x, y, z);
					if (GD.Randf() < RANDOM_BLOCK_PROBABILITY)
					{
						random_data[vec] = GD.Randi() % 29 + 1;
					}
				}
			}
		}
		return random_data;
	}

	public static VexelDict Flat(Vector3I chunk_position)
	{
		VexelDict data = new VexelDict();

		if (chunk_position.Y != -1)
		{
			return data;
		}

		for (int x = 0; x < VoxelWorld.CHUNK_SIZE; x++)
		{
			for (int z = 0; z < VoxelWorld.CHUNK_SIZE; z++)
			{
				data[new Vector3I(x, 2, z)] = 3;
				//data[new Vector3I(x, 1, z)] = 2;
				//data[new Vector3I(x, 0, z)] = 2;
				//data[new Vector3I(x, -1, z)] = 9;
			}
		}
		return data;
	}

	public static VexelDict OriginGrass(Vector3I chunk_position)
	{
		if (chunk_position == Vector3I.Zero)
		{
			return new VexelDict { { Vector3I.Zero, 3 } };
		}
		return new VexelDict();
	}
}
